<template>
  <a-modal
    :title="title"
    :width="1200"
    :visible="visible"
    :maskClosable="false"
    :confirmLoading="confirmLoading"
    :okButtonProps="{ props: {disabled: disableSubmit} }"
    @ok="handleOk"
    @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
      <!-- 主表单区域 -->
      <a-form :form="form">
        <a-row>

          <a-col :span="12">
            <a-form-item label="机构" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-select-depart v-decorator="['office']" :trigger-change="true" :disabled='true'/>
            </a-form-item>
          </a-col>

          <a-col :span="12">
            <a-form-item label="系统名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="[ 'systemName', validatorRules.systemName]" placeholder="请输入系统名称" readonly="readonly"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="审核" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-select v-decorator="[ 'type', {}]" disabled="disabled">
                <a-select-option value="1">等待审核</a-select-option>
                <a-select-option value="2">已通过</a-select-option>
                <a-select-option value="3">未通过</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>

        </a-row>
      </a-form>

      <!-- 子表单区域 -->
      <a-tabs v-model="activeKey" @change="handleChangeTabs">
        <a-tab-pane tab="服务器申请附表" :key="refKeys[0]" :forceRender="true">
          <j-editable-table
            :ref="refKeys[0]"
            :loading="jinanGovernmentLedgerAttachedTable.loading"
            :columns="jinanGovernmentLedgerAttachedTable.columns"
            :dataSource="jinanGovernmentLedgerAttachedTable.dataSource"
            :maxHeight="300"
            :rowNumber="true"
            :rowSelection="true"
            :actionButton="false"
          />
        </a-tab-pane>

      </a-tabs>

    </a-spin>
  </a-modal>
</template>

<script>

  import pick from 'lodash.pick'
  import { FormTypes,getRefPromise } from '@/utils/JEditableTableUtil'
  import { JEditableTableMixin } from '@/mixins/JEditableTableMixin'
  import JEditableTable from '@/components/jeecg/JEditableTable'
  import JDate from '@/components/jeecg/JDate'  
  import JSelectDepart from '@/components/jeecgbiz/JSelectDepart'
  import JMultiSelectTag from "@/components/dict/JMultiSelectTag"
  import JUpload from '@/components/jeecg/JUpload'
  import { httpAction, getAction } from '@/api/manage'

  export default {
    name: 'CloudMoneyModal',
    mixins: [JEditableTableMixin],
    components: {
      JDate,
      JSelectDepart,
      JMultiSelectTag,
      JUpload,
      JEditableTable
    },
    data() {
      return {
        labelCol: {
          span: 6
        },
        wrapperCol: {
          span: 16
        },
        labelCol2: {
          span: 3
        },
        wrapperCol2: {
          span: 20
        },
        disBool:true,
        disableSubmit:false,
        // 新增时子表默认添加几行空数据
        addDefaultRowNum: 1,
        validatorRules: {
          updateTime:{},
          office:{},
          principal:{},
          principalPhone:{rules: [{validator: this.validatePhone}]},
          principalMail:{rules: [{validator: this.validateEmail}]},
          linkman:{},
          linkmanPhone:{rules: [{validator: this.validatePhone}]},
          linkmanMail:{rules: [{validator: this.validateEmail}]},
          systemName:{},
          mainUses:{},
          tos:{},
        },
        refKeys: ['jinanGovernmentLedgerAttached', ],
        tableKeys:['jinanGovernmentLedgerAttached', ],
        activeKey: 'jinanGovernmentLedgerAttached',
        // 服务器申请附表
        jinanGovernmentLedgerAttachedTable: {
          loading: false,
          dataSource: [],
          columns: [
            {  //这一个隐藏字段不能去掉，解决360浏览器不兼容问题
              title: '服务器名称',
              key: '',
              type: FormTypes.hidden,
              defaultValue: '',
              placeholder: '请输入${title}',
              align:"center",
            },
            {
              title: '服务器名称',
              key: 'serverName',
              type: FormTypes.input,
              defaultValue: '',
              placeholder: '请输入${title}',
              align:"center",
              disabled:"true",
            },
            {
              title: '年度云服务费',
              key: 'yearMoney',
              type: FormTypes.input,
              defaultValue: '',
              placeholder: '',
              align:"center",
              disabled:"true",
            },
            {
              title: '年度节省云服务费',
              key: 'yearSaveMoney',
              type: FormTypes.input,
              defaultValue: '',
              placeholder: '',
              align:"center",
              disabled:"true",
            },
            {
              title: '实时云服务费',
              key: 'lastYearMoney',
              type: FormTypes.input,
              defaultValue: '',
              placeholder: '',
              align:"center",
              disabled:"true",
            },
            {
              title: '实时节省云服务费',
              key: 'lastYearSaveMoney',
              type: FormTypes.input,
              defaultValue: '',
              placeholder: '',
              align:"center",
              disabled:"true",
            },
          ]
        },
        url: {
          // add: "/jinanServer/jinanGovernmentLedgerMain/add",
          edit: "/jinanDredge/dredgeMain/edit",
          jinanGovernmentLedgerAttached: {
            list: '/jinanCloudMoney/cloudMoney/queryJinanGovernmentLedgerAttachedByMainId'
          },
          // getMoney:"/jinanDredge/dredgeMain/getMoney"
        }
      }
    },
    methods: {
      // handelChange(event){
      //   const { type, row, column, value, target } = event;
      //   let openTime = row.openTime;
      //   if(openTime==""){
      //     let date = new Date();
      //     openTime = date.getFullYear()+"-"+date.getMonth()+"-"+date.getDay();
      //   }
      //   const obj = {rowId:row.id,date:openTime,ip:row.ipSite}
      //   switch (type) {
      //     case FormTypes.date :
      //       if(column.key=='openTime'){
      //         this.getMoney(obj,target,row,openTime);
      //       }
      //       break;
      //     case FormTypes.input:
      //       if(column.key=='ipSite'){
      //         this.getMoney(obj,target,row,openTime);
      //       }
      //       break;
      //   }
      // },
      // getMoney(params,target,row,openTime){
      //   getAction(this.url.getMoney, params).then(res => {
      //     target.setValues([{
      //         rowKey: row.id,
      //         values: { openTime: openTime,auditMoney: res.data.auditMoney, applyMoney: res.data.applyMoney,saveMoney:res.data.saveMoney }
      //       }])
      //   }).finally(() => {
      //   })
      // },
      getAllTable() {
        let values = this.tableKeys.map(key => getRefPromise(this, key))
        return Promise.all(values)
      },
      /** 调用完edit()方法之后会自动调用此方法 */
      editAfter() {
        let fieldval = pick(this.model,'updateTime','office','principal','principalPhone','principalMail','linkman','linkmanPhone','linkmanMail','systemName','mainUses','tos','type','remarks'
        ,'openTime','ipSite','vpn','auditMoney','applyMoney','saveMoney', 'filePath','auditFilePath','open')
        this.$nextTick(() => {
          fieldval.type= this.disableSubmit?fieldval.type:"2";
          this.form.setFieldsValue(fieldval)
        })
        // 加载子表数据
        if (this.model.id) {
          let params = { id: this.model.id }
          this.requestSubTableData(this.url.jinanGovernmentLedgerAttached.list, params, this.jinanGovernmentLedgerAttachedTable)
        }
      },
      /** 整理成formData */
      classifyIntoFormData(allValues) {
        let main = Object.assign(this.model, allValues.formValue)

        return {
          ...main, // 展开
          jinanGovernmentLedgerAttachedList: allValues.tablesValue[0].values,
        }
      },
      validateError(msg){
        this.$message.error(msg)
      },
      validateEmail(rule, value, callback){
        if(!value){
          callback()
        }else{
          if(new RegExp(/^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/).test(value)){
            callback()
          }else{
            callback("请输入正确格式的邮箱!")
          }
        }
      },
        //2020.4.22  14:56  雪糕修改正则表达式检验手机号输入格式（长度）。
        validatePhone(rule, value, callback){
            if(!value){
                callback()
            }else{
                if(new RegExp(/^1[3|4|5|7|8][0-9]\d{8}$/).test(value)){
                    callback()
                }else{
                    callback("请输入正确格式的手机号码!");
                }
            }
        },
      
      
    }
  }
</script>

<style scoped>
</style>